import { Controller, Get, Inject, Post, Body, Put, Param, Delete } from '@nestjs/common';
import { BookService } from './book.service';
import { Book } from './book.entity';
import { ApiTags, ApiOperation } from '@nestjs/swagger';

@Controller('book')
@ApiTags('Book')
export class BookController {
    constructor(
        @Inject(BookService) private readonly bookservice:BookService
    ){}
    
    @ApiOperation({summary:'查询所有书籍'})
    @Get()
    async findAll(){
        return await this.bookservice.findAll()
    }

    @ApiOperation({summary:'查询某个书籍'})
    @Get(':id')
    async findOneBook(@Param('id') id:string){
        return await this.bookservice.findOneBook(id)
    }

    @ApiOperation({summary:'创建一本书'})
    @Post()
    async createBoook(@Body() book:Book){
        await this.bookservice.createBook(book)
    }

    @ApiOperation({summary:'修改某个书籍'})
    @Put(':id')
    async modifyBook(@Param('id') id:string,@Body() book:Book){
        await this.bookservice.modifyBook(id,book)
    }

    @ApiOperation({summary:'删除某个书籍'})
    @Delete(':id')
    async deleteBook(@Param('id') id:string){
        await this.bookservice.deleteBook(id)
    }
}
